<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #app{
            padding: 10px;
        }
        .input-box{
            margin: 10px;
            display: flex;
            align-items: center;
        }
        .input-box input{
            flex: 1;
            height: 30px;
            border: 1px solid #ccc;
            border: none;
            padding-left: 20px;
            border-radius: 5px;
            background-color: gainsboro;
        }
        .input-box span{
            text-align: center;
            color: lightseagreen;
            width: 60px;
        }
        .list{
            margin: 10px;
        }
        .list .task{
            margin: 20px 0;
            display: flex;
            justify-content: space-between;
            padding: 15px;
            background-color: red;
            color: white;
            font-size: 14px;
        }
        .list .task.finished{
            background-color: lightseagreen;
        }
        .empty{
            text-align: center;
            margin: 50px 0;
            color: red;
        }
        .box{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            font-size: 14px;
            padding: 10px;
            box-sizing: border-box;
        }
        .box div{
            height: 15px;
            width: 25%;
            text-align: center;
            line-height: 15px;
            color: white;
            background-color: lightseagreen;
            padding: 10px;
            border-radius: 10px;
        }
        .box div:nth-child(3){
            background-color: red;
        }
        #app>span{
            font-weight: 800;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="input-box">
            <input type="text" placeholder="输入任务名称" v-model="inputText"> 
            <span @click="add">添加</span>
        </div>
        <div class="box">
            <div>全部任务()</div>
            <div>已完成()</div>
            <div>未完成()</div>
        </div>
        <span>任务列表</span>
        <div class="list">
            <div :class="{ task: true, finished: item.status }" v-for="(item,index) in tasklist" :key="index">
                <input type="checkbox" @click="changeStatus(item)">
                <div>{{item.id}}</div>
                <div class="name">{{item.name}}</div>
                <span @click="del(index)">删除</span>
            </div>
            <div class="empty" v-show="tasklist.length == 0">任务列表空空如也!</div>
        </div>
    </div>
    <script src="./vue-2.5.21.js"></script>
    <script>
        var v = new Vue({
            el:'#app',
            data:{
                inputText:'',
                tasklist:[
                ]
            },
            methods:{
                add(){ //添加任务
                    if( this.inputText ){ 
                        //构造一个任务对象
                        var obj = { id: this.tasklist.length + 1 ,name:this.inputText, status: false };
                        //将任务对象 添加到任务列表中
                        this.tasklist.push( obj );
                        //清空输入框
                        this.inputText = '';
                    }
                },
                changeStatus(item){ 
                    item.status = !item.status;
                },
                del(index){
                    this.tasklist.splice(index,1)
                }     
            }
        })
    </script>
</body>
</html>